# file: runme.rb

# This file illustrates the C++ interface created by SWIG.
# All of our C++ classes get converted into Ruby classes.

require 'SODxml'

# ----- Object creation -----

print "Initialize:\n"
path = "resources/test.xml"
points1 = [[1, 2, 3], [4, 5, 6], [7, 9, 8]]
points2 = [[9, 8, 7], [4, 5, 6], [7, 9, 8]]
sg_values = [101, 102, 103, 104, 105, 106]
puts points1.length
puts points2.length
puts sg_values.length

file = SODxml::File.new()
building = SODxml::Building.new()
print "    Set File #{file}\n"

# ----- Set building ------

bar1 = SODxml::Bar.new()
bar1.set_NOS(3)
bar1.set_length(24.0)
bar1.set_width(12.5)
bar1.set_direction(SODxml::Point.new(1,2,3))
bar1.set_origin(SODxml::Point.new(0,0,200))

points1Vec = SODxml::PointVector.new( points1.length )
#puts footprintVec.methods.sort
 0.upto(points1.length-1) do |i|
    points1Vec[i] = SODxml::Point.new(points1[i][0], points1[i][1], points1[i][2])
 end
 bar1.Points(points1Vec)


bar2 = SODxml::Bar.new()
bar2.set_NOS(3)
bar2.set_length(24.0)
bar2.set_width(12.5)
bar2.set_direction(SODxml::Point.new(1,2,3))
bar2.set_origin(SODxml::Point.new(0,0,200))

points2Vec = SODxml::PointVector.new( points2.length )
#puts footprintVec.methods.sort
 0.upto(points2.length-1) do |i|
    points2Vec[i] = SODxml::Point.new(points2[i][0], points2[i][1], points2[i][2])
 end
 bar2.Points(points2Vec)


sgvaluesVec = SODxml::DoubleVector.new( sg_values.length )
#puts footprintVec.methods.sort
 0.upto(sg_values.length-1) do |i|
   sgvaluesVec[i] = sg_values[i]
 end


barsVec = SODxml::BarVector.new( 2 )
barsVec[0] = bar1
barsVec[1] = bar2

building.Bars(barsVec)
building.SgValues(sgvaluesVec)

#point = SODxml::Point.new();
#point.x = 101
#point.y = 102
#point.z = 103
#point_vec = SODxml::PointVector.new(1);
#point_vec[0] = point;
#bar = SODxml::Bar.new();
#bar.points = point_vec;
#bar_vec = SODxml::BarVector.new(1);
#bar_vec[0] = bar;

#building.set_bars(bar_vec)
#building.dump_bars()


# int a[3] 
#building.set_position(12.5)
#building.set_direction(5.5)
#      
	  
# ----- Access a static member -----

# print "\n building.number_of_storeys: #{building.get_NOS()} set!\n"
# print "building.length: #{building.get_length()} set!\n"
# print "building.width: #{building.get_width()} set!\n"

# ----- Call some methods -----

print "\nHere are some properties of the shapes:\n"

  print "    #{file}\n"
  
#file.read(path, building)
path = "resources/test_write.xml"
file.write(path, building)
# building = file.read(path)

# ----- Show new Values -----

print "\nbuilding.number_of_storeys: #{building.Bars()[0].get_NOS()} \n"
print "building.bars[0].length: #{building.Bars()[0].get_length()} \n"
print "building.bars[0].width: #{building.Bars()[0].get_width()} \n"
print "building.bars[0].get_sgValues: #{building.SgValues()} \n"

# Notice how the Shape#area() and Shape#perimeter() functions really
# invoke the appropriate virtual method on each object.

print "Goodbye\n"
